﻿using FreesenseSubAPI.InspProcess;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreesenseSubAPI.Camera
{
    public class CameraBase
    {
        public string cameraID;
        public CameraBaseState Fram_W;//白图
        public CameraBaseState Fram_Bl;//黑图
        public CameraBaseState Fram_Gr;//灰图
        public CameraBaseState Fram_R;//红
        public CameraBaseState Fram_G;//绿
        public CameraBaseState Fram_B;//蓝
        public CameraBaseState Fram_Dust1;//侧光1
        public CameraBaseState Fram_Dust2;//侧光2
        //public bool CameraConctrlDevice=false;//本相机线程是否控制侧光及背光控制，默认不控制,仅供本相机线程判断是否有控制权
        //public  bool CameraConctrlChangeColor = false;//本相机线程是否控制切图，默认不控制（四相机公用一个切图，默认第一个切图）
        public delegate void RefrushConctrlEventHandler(ResultDisplayRowResult aisrow);
        public delegate void RefrushContinueCapturePicEventHandler(Bitmap bt);
        public bool CameraConnectState = false;
        public System.Work.Hardware.eBUSCamera InitCamera(CameraInfomation cInfo)
        {
            #region 每个相机单独初始化，传入参数为相机索引，功能保留
            try
            {
                System.Work.Hardware.eBUSCamera tempcamera = new System.Work.Hardware.eBUSCamera(cInfo.MacAddr);
                if (tempcamera.CameraStatus == System.Work.Hardware.Camera.enumStatus.NoDriver)
                {
                    throw new ArgumentException(string.Format(cInfo.MacAddr + "相机未安装驱动！"));
                }
                if (tempcamera.CameraStatus == System.Work.Hardware.Camera.enumStatus.NoCameraIPConfig)
                {
                    tempcamera.SetGevCamIPConfiguration(cInfo.LocalAdapterName, cInfo.CameraIp, cInfo.SubnetMask, cInfo.DefaultGateway);
                    tempcamera.SetGevNetworkAdapterInfo(cInfo.LocalAdapterName, cInfo.LocalIP, cInfo.SubnetMask, cInfo.DefaultGateway);
                    tempcamera.Close();
                    tempcamera = new System.Work.Hardware.eBUSCamera(cInfo.MacAddr);
                }
                if (tempcamera != null && tempcamera.CameraStatus == System.Work.Hardware.Camera.enumStatus.Running)
                {
                    CameraConnectState = true;
                    tempcamera.SetExternTrigger(3);
                    tempcamera.SetLineTriggerSource(false);
                    tempcamera.StartContinuouShot();
                    return tempcamera;
                }
                else
                    return null;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
                //BpjbCommon.Net.Core.BpEventHandler.ErrHandler(string.Format(MacAddr+ "相机连接失败：{0}！", ex.Message), BpjbCommon.Net.Core.ErrType.Warning);
            }
            #endregion 每个相机单独初始化，传入参数为相机索引
        }
    }

    public enum InspState
    {
        //-5为连续，-6为单帧，-4为sumura读图测试
        Muce=-3,//目测图，先上清灰、下清灰、在目测
        SideLight = -2,//侧光
        None = -1,
        WhitePoint = 0,
        FramePoint = 1,//边框校正
        RGBPoint = 2,
        Red = 3,//红图
        Green = 4,//绿图
        Blue = 5,//蓝图
        Black = 6,//黑图
        White = 7,//白图
        Uniformity = 8,
        Gray = 9,//灰图
        Fliker = 10,//闪图
        OddRow = 11,//奇数行
        EvenRow = 12,//偶数行
        OddColumn = 13,//奇数列
        EvenColumn = 14,//偶数列
        LowUIFlicker = 15,
        Pink = 16,//粉红、桃红
        TT = 17,
        Dark_Scratch = 18,//暗划
        LowFrequence_Grayscale = 19,//低频灰阶
        LowFrequence_White = 20,//低频白色
        SoftBlue = 21,//浅蓝
        Yellow = 22,//黄
        Lowfre_Blackscale = 23,//低频黑色
        FlickerPI1=24,//PI1闪图
        FlickerPI2 = 25,//PI2闪图
        NoPic=26,//放电图
        NewBlue=27,//新蓝图
        NewFlicker=28//新flicker
    }
}
